package com.ruoyi.web.controller.tools;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.tools.ToolsWord;
import com.ruoyi.system.service.tools.IToolsWordService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单词学习Controller
 * 
 * @author syc
 * @date 2022-12-05
 */
@RestController
@RequestMapping("/tools/word")
public class ToolsWordController extends BaseController {
	@Autowired
	private IToolsWordService toolsWordService;

	/**
	 * 查询单词学习列表
	 */
	@PreAuthorize("@ss.hasPermi('tools:word:list')")
	@GetMapping("/list")
	public TableDataInfo list(ToolsWord toolsWord) {
		startPage();
		List<ToolsWord> list = toolsWordService.selectToolsWordList(toolsWord);
		return getDataTable(list);
	}

	/**
	 * 导出单词学习列表
	 */
	@PreAuthorize("@ss.hasPermi('tools:word:export')")
	@Log(title = "单词学习", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, ToolsWord toolsWord) {
		List<ToolsWord> list = toolsWordService.selectToolsWordList(toolsWord);
		ExcelUtil<ToolsWord> util = new ExcelUtil<ToolsWord>(ToolsWord.class);
		util.exportExcel(response, list, "单词学习数据");
	}

	/**
	 * 获取单词学习详细信息
	 */
	@PreAuthorize("@ss.hasPermi('tools:word:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(toolsWordService.selectToolsWordById(id));
	}

	/**
	 * 新增单词学习
	 */
	@PreAuthorize("@ss.hasPermi('tools:word:add')")
	@Log(title = "单词学习", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody ToolsWord toolsWord) {
		return toAjax(toolsWordService.insertToolsWord(toolsWord));
	}

	/**
	 * 修改单词学习
	 */
	@PreAuthorize("@ss.hasPermi('tools:word:edit')")
	@Log(title = "单词学习", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody ToolsWord toolsWord) {
		return toAjax(toolsWordService.updateToolsWord(toolsWord));
	}

	/**
	 * 删除单词学习
	 */
	@PreAuthorize("@ss.hasPermi('tools:word:remove')")
	@Log(title = "单词学习", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(toolsWordService.deleteToolsWordByIds(ids));
	}
	
	@PreAuthorize("@ss.hasPermi('tools:word:edit')")
	@Log(title = "单词学习", businessType = BusinessType.UPDATE)
	@PutMapping("/updateList")
	public AjaxResult editLIst(@RequestBody List<ToolsWord> toolsWordList) {
		System.out.println(toolsWordList.toString());
		int result = toolsWordService.updateToolsWordList(toolsWordList);
		return toAjax(1);
	}
}
